package com.ruoyi.project.purchase.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.purchase.domain.pojo.DepotDetailBean;
import com.ruoyi.project.purchase.domain.pojo.DepotHeadItem;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.purchase.domain.ProjectClearance;
import com.ruoyi.project.purchase.service.IProjectClearanceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 项目清仓Controller
 *
 * @author you
 * @date 2022-09-27
 */
@RestController
@RequestMapping("/purchase/projectClearance")
public class ProjectClearanceController extends BaseController
{
    @Autowired
    private IProjectClearanceService projectClearanceService;

    /**
     * 查询项目清仓列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:projectClearance:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectClearance projectClearance)
    {
        startPage();
        projectClearance.setType("其他");
        projectClearance.setSubType("项目总清单");
        projectClearance.setProjectStatus("1");//查询已结束的项目
        List<ProjectClearance> list = projectClearanceService.selectProjectClearanceList(projectClearance);
        return getDataTable(list);
    }

    /**
     * --项目总清单
     * 获取项目总清单详细信息
     */
    @GetMapping(value = "/selectByDepotId/{id}")
    public AjaxResult selectByDepotId(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectClearanceService.selectRyDepotDetailByDepotId(id));
    }


    /**
     * --项目清仓
     * 本质上是项目库出库，总库入库操作
     * 要记录出入库记录
     * 根据主表修改单据子表信息
     */
    @RequestMapping("/editProjectClearance")
    public AjaxResult editProjectClearance(@RequestBody DepotHeadItem depotHeadItem){
        System.out.println("depotHeadItem---->" + depotHeadItem);
        return  projectClearanceService.editProjectClearance(depotHeadItem);
    }







    /**
     * 导出项目清仓列表
     */
    @PreAuthorize("@ss.hasPermi('purchase:projectClearance:export')")
    @Log(title = "项目清仓", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectClearance projectClearance)
    {
        List<ProjectClearance> list = projectClearanceService.selectProjectClearanceList(projectClearance);
        ExcelUtil<ProjectClearance> util = new ExcelUtil<ProjectClearance>(ProjectClearance.class);
        util.exportExcel(response, list, "项目清仓数据");
    }

    /**
     * 获取项目清仓详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchase:projectClearance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(projectClearanceService.selectProjectClearanceById(id));
    }

    /**
     * 新增项目清仓
     */
    @PreAuthorize("@ss.hasPermi('purchase:projectClearance:add')")
    @Log(title = "项目清仓", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectClearance projectClearance)
    {
        return toAjax(projectClearanceService.insertProjectClearance(projectClearance));
    }

    /**
     * 修改项目清仓
     */
    @PreAuthorize("@ss.hasPermi('purchase:projectClearance:edit')")
    @Log(title = "项目清仓", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectClearance projectClearance)
    {
        return toAjax(projectClearanceService.updateProjectClearance(projectClearance));
    }

    /**
     * 删除项目清仓
     */
    @PreAuthorize("@ss.hasPermi('purchase:projectClearance:remove')")
    @Log(title = "项目清仓", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectClearanceService.deleteProjectClearanceByIds(ids));
    }
}
